package com.fbinggun.dt.task.conditions;

import com.fbinggun.dt.DailyTask;
import com.fbinggun.dt.task.Task;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityBreedEvent;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Bred extends Conditions{
    List<String> list = new ArrayList<>();
    public Bred(String id, ConfigurationSection config, Task task) {
        super(id, config, task);
        list=config.getStringList("Type");
    }
    @EventHandler
    public void on(EntityBreedEvent event) throws SQLException, ClassNotFoundException {
        if(event.getBreeder()==null){
            return;
        }
        if(event.getBreeder() instanceof Player){
            Player player = (Player) event.getBreeder();
            LivingEntity entity= event.getEntity();
            if(isRun(player)){
                String entityName = entity.getType().getName().toUpperCase();
                if (list == null || list.size() == 0) {
                    addCount(player, 1);
                } else {
                    if (list.contains(entityName)) {
                        addCount(player, 1);
                    }
                }
            }
        }
    }
}
